package br.com.salaodebeleza.view;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.inject.Inject;

import br.com.salaodebeleza.business.TbClienteBC;
import br.com.salaodebeleza.domain.TbCliente;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractEditPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;

@ViewController
@PreviousView("./tbCliente_list.jsf")
public class TbClienteEditMB extends AbstractEditPageBean<TbCliente, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private TbClienteBC tbClienteBC;
	
	private Map<String,String> ufs = new TreeMap<String, String>();

	
	public TbClienteEditMB() {
		ufs.put("AC", "AC");  
		ufs.put("AL", "AL");  
		ufs.put("AP", "AP");
		ufs.put("AM", "AM");
		ufs.put("BA", "BA");
		ufs.put("CE", "CE");
		ufs.put("DF", "DF");
		ufs.put("ES", "ES");
		ufs.put("GO", "GO");
		ufs.put("MA", "MA");
		ufs.put("MT", "MT");
		ufs.put("MS", "MS");
		ufs.put("MG", "MG");
		ufs.put("PA", "PA");
		ufs.put("PB", "PB");
		ufs.put("PR", "PR");
		ufs.put("PE", "PE");
		ufs.put("PI", "PI");
		ufs.put("RJ", "RJ");
		ufs.put("RN", "RN");
		ufs.put("RS", "RS");
		ufs.put("RO", "RO");
		ufs.put("RR", "RR");
		ufs.put("SC", "SC");
		ufs.put("SP", "SP");
		ufs.put("SE", "SE");
		ufs.put("TO", "TO");
	}
	
	@Override
	@Transactional
	public String delete() {
		this.tbClienteBC.delete(getId());
		return getPreviousView();
	}
	
	@Override
	@Transactional
	public String insert() {
		this.tbClienteBC.insert(getBean());
		return getPreviousView();
	}
	
	@Override
	@Transactional
	public String update() {
		this.tbClienteBC.update(getBean());
		return getPreviousView();
	}
	
	@Override
	protected void handleLoad() {
		setBean(this.tbClienteBC.load(getId()));
	}
	
	public void validarEspacoBranco(FacesContext context, UIComponent componet, Object object){
		String valor = (String) object;
		if(valor.trim().equals("")){
			((UIInput) componet).setValid(false);
			String mensagem = "Valor invalido, preencha com caracteres diferentes de espaço.";
			FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, mensagem, mensagem);
			context.addMessage(componet.getClientId(context), facesMessage);
		}
	}
	
	public Map<String, String> getUfs() {
		return ufs;
	}
	
	

}